# -*- coding: utf-8 -*-
# =============================================================================
#     FileName:
#         Desc:
#       Author:
#        Email:
#     HomePage:
#      Version:
#   LastChange:
#      History:
# =============================================================================

class BaseEnumItem(object):
    def __init__(self, item_value, item_desc):
        self.item_value = item_value
        self.item_desc = item_desc

    def __eq__(self, other):
        return self.item_value == other

    def __int__(self):
        return self.item_value

    def __str__(self):
        return "{0}({1})".format(self.item_desc, self.item_value)

    def __repr__(self):
        return "{0}({1})".format(self.item_desc, self.item_value)


class BaseEnum(object):

    @classmethod
    def get_items(cls):
        item_list = []
        for key, value in vars(cls).items():
            if isinstance(value, BaseEnumItem):
                item_list.append(value)
        return item_list

    @classmethod
    def get_item(cls, item_value, default_item=None):
        for item in cls.get_items():
            if item.item_value == item_value:
                return item
        return default_item

    @classmethod
    def get_item_choices(cls):
        item_choices = list()
        for item in cls.get_items():
            item_choices.append((item.item_value, item.item_desc))
        return item_choices

    @classmethod
    def get_form_item_choices(cls):
        item_choices = list()
        for item in cls.get_items():
            item_choices.append((str(item.item_value), str(item.item_desc)))
        return item_choices
